<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>购物车 - {wc:$webname}触屏版</title>
    <meta content="app-id=518966501" name="apple-itunes-app" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no, maximum-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    
    <link href="{G_TEMPLATES_CSS}/mobile/comm.css" rel="stylesheet" type="text/css" />
	
	<link href="{G_TEMPLATES_CSS}/mobile2/comm.css" rel="stylesheet" type="text/css" />
	
	
	<link href="{G_TEMPLATES_CSS}/mobile/cartList.css" rel="stylesheet" type="text/css" />
	<script src="{G_TEMPLATES_JS}/mobile/jquery190.js" language="javascript" type="text/javascript"></script>
	<script id="pageJS" data="{G_TEMPLATES_JS}/mobile/Cartindex.js" language="javascript" type="text/javascript"></script>
	<script type="text/javascript">
		var cartListInfo = {wc:$yjCartList};
	</script>
	<style type="text/css">
		.yj-mask{width: 100%;height: 100%;background: black;position: absolute;top: 0px;z-index: 101;opacity: 0.7;}
		.yj-content{width: 80%;max-height:80%;background: white;position: absolute;top: 10%;left: 10%;z-index: 102;overflow-y: auto;}
		.yj-topbar{width:100%;height:35px;background: #f8f8f8;border-top: 1px solid #dfdfdf;border-bottom 1px solid #efefef;border-bottom: 1px solid #dfdfdf;position: sticky;top: 0px;text-align: center;line-height: 35px;}
		.yj-content table{width: 100%;}
		.yj-content table td{height: 35px}
		.yj-allrand{position: absolute;cursor: pointer;right: 13%;}
		.yj-button{padding: 5px 7px;background: red;color: white;border-radius: 3px;cursor: pointer;}
		.yj-bottombar{text-align: center;bottom: 0px;padding-top: 10px;padding-bottom: 10px;position: sticky;background: #f8f8f8;border-top: 1px solid #dfdfdf;border-bottom: 1px solid #dfdfdf;}
		.yj-xj{text-align: center;padding: 5px 0;color: white;background: #f60;margin: 0 auto;border-radius: 3px;}
		.yj-xjs{word-break: normal;word-wrap: break-word;overflow-y: auto;margin-bottom: 5px;padding: 0 5px;color: #999;text-align: center;}
		.yj-random{text-align: center;}
		.ygcode{text-align: center;}
	</style>
</head>
<body>
<div class="h5-1yyg-v1" id="loadingPicBlock">
    
<!-- 栏目页面顶部 -->


<!-- 内页顶部 -->

   <!--  <header class="g-header">
        <div class="head-l">
	        <a href="javascript:;" onclick="history.go(-1)" class="z-HReturn"><s></s><b>返回</b></a>
        </div>
        <h2>购物车</h2>
        <div class="head-r">
	        
        </div>
    </header> -->

	 <!--首页头部-->
        <div class="m-block-header" style=""><a href="./1元云购 - 惊喜无限_files/1元云购 - 惊喜无限.html" class="m-public-icon m-1yyg-icon"></a></div>
     <!--首页头部 end-->
	
    <input name="hidLogined" type="hidden" id="hidLogined" value="1" />
    <section class="clearfix g-Cart">
	    {wc:if $shop!=0}
	        <article class="clearfix m-round g-Cart-list">
	            <ul id="cartBody">
				{wc:php:start}
				$buyshopmoney=0;
				{wc:php:end}
	            {wc:loop $shoplist  $key $val}
				{wc:php:start}
            	   $num = count($shoplist);
				   $buyshopmoney+=$Mcartlist[$val['id']]['money'];
                {wc:php:end}    
					<li>		            
						<a class="fl u-Cart-img" href="{WEB_PATH}/mobile/mobile/item/{wc:$val['id']}">
							<img src="{G_TEMPLATES_IMAGE}/loading.gif" src2="{G_UPLOAD_PATH}/{wc:$val['thumb']}" border="0" alt=""/>
						</a>
						<div class="u-Cart-r">
							<p class="z-Cart-tt"><a href="{WEB_PATH}/mobile/mobile/item/{wc:$val['id']}" class="gray6">(第{wc:$val['qishu']}期){wc:$val['title']}</a></p>
							<ins class="z-promo gray9">剩余<em class="arial">{wc:$val['zongrenshu']-$val['canyurenshu']}</em>人次  </ins>
							<p class="gray9">总共{wc:fun:_cfg('web_name_two')}：<em class="arial">{wc:$Mcartlist[$val['id']]['num']}</em>人次/<em class="orange arial">￥{wc:$Mcartlist[$val['id']]['money']}.00</em></p>
							<p class="f-Cart-Other">
								<a href="javascript:;" class="fr z-del" name="delLink" cid="{wc:$val['id']}"></a>
								<a href="javascript:;" class="fl z-jian {wc:if $Mcartlist[$val['id']]['num']==1}z-jiandis{wc:if:end}"
								attr_limit_buy="{wc:$val['limit_buy']}" attr_limit_buys="{wc:$val['limit_buys']}"
								>-</a>
								
								<input id="txtNum{wc:$val['id']}" name="num" type="text" maxlength="7" yunjiage = "{wc:$val['yunjiage']}" attr_limit_buy="{wc:$val['limit_buy']}" attr_limit_buys="{wc:$val['limit_buys']}" value="{wc:$Mcartlist[$val['id']]['num']}" class="fl z-amount" readonly />
								<a href="javascript:;"
attr_limit_buy="{wc:$val['limit_buy']}" attr_limit_buys="{wc:$val['limit_buys']}"
								class="fl z-jia {wc:if $Mcartlist[$val['id']]['num']==$val['zongrenshu']}z-jiadis{wc:if:end}">+</a>
								<input type="hidden" value="{wc:$Mcartlist[$val['id']]['num']}" />
								<input type="hidden" value="{wc:$val['zongrenshu']-$val['canyurenshu']}" />
							</p>
						</div>
						<div class="yj-xjs" id="s{wc:$val['id']}" style="display: none;"></div>
						<div class="yj-xj" id="{wc:$val['id']}" onclick="input_yg_code(this);">输入云购码</div>
					</li>
				{wc:loop:end}
				
	            </ul>
	        </article>
	       
	    <div id="divBtmMoney" class="g-Total-bt"><p>总共{wc:fun:_cfg('web_name_two')}
			<span class="orange arial z-user">{wc:$num}</span>个商品  合计金额：
			<span class="orange arial">{wc:$buyshopmoney}.00</span> 元</p>
			<a href="javascript:;" class="orgBtn">结 算</a>
		</div>
	{wc:if:end}
	    <div id="divNone" class="haveNot z-minheight" style="display:none"><s></s><p>抱歉，您的购物车没有商品记录！</p>
		</div>
		
    </section>
    <div class="hot-recom">
    	<div class="title thin-bor-top gray6"><span><b class="z-set"></b>人气推荐</span><em></em></div>
    	<div class="goods-wrap thin-bor-top">
    		<ul class="goods-list clearfix">
				{wc:loop $rec_goods $goods}
    			<li>
    				<a href="/?/mobile/mobile/item/{wc:$goods['id']}" class="g-pic">
    					<img src="{G_UPLOAD_PATH}/{wc:$goods['thumb']}" width="136" height="136">
    				</a>
    				<p class="g-name">
    					<a href="/?/mobile/mobile/item/{wc:$goods['id']}">(第{wc:$goods['qishu']}期){wc:$goods['title']}</a>
    				</p>
    				<ins class="gray9">价值:￥{wc:$goods['money']}</ins>
    				<div class="btn-wrap">
    					<div class="Progress-bar">
    						<p class="u-progress">
    							<span class="pgbar" style="width:{wc:$goods['buy_rate']}%;">
    								<span class="pging"></span>
    							</span>
    						</p>
    					</div>
	    				<div class="gRate" data-productid="23458">
	    					<a href="javascript:;" class="add2" codeid="{wc:$goods['id']}">
	    						<s></s>
	    					</a>
    					</div>
    				</div>
    			</li>
    			{wc:loop:end}
    		</ul>
    	</div>
    </div>
    
<div class="footer clearfix" style="bottom: 0px;">
    <ul>
        <li class="f_home"><a href="?/mobile/mobile/"><i></i>云购</a></li>
        <li class="f_announced"><a href="?/mobile/mobile/lottery" ><i></i>最新揭晓</a></li>
        <li class="f_single"><a href="?/mobile/shaidan/"><i></i>晒单</a></li>
        <li class="f_car"><a href="?/mobile/cart/cartlist"  class="hover"><i></i>购物车</a></li>
        <li class="f_personal"><a href="?/mobile/user/login"><i></i>我的云购</a></li>
    </ul>
</div>


<div class="yj-mask" style="display: none;" onclick="hide_mask();">
</div>
<div class="yj-content" style="display: none;">
	<div class="yj-topbar"><span style="position: absolute;float: left;left: 32%;">输入云购码</span><span class="yj-allrand" onclick="all_rand()">全部机选</span></div>
	<table width="100%"  id="yj-table">
	</table>
	<div class="yj-bottombar" style="text-align: center;">
		<span class="yj-button" onclick="code_ok()">确定</span>
		<span class="yj-button" onclick="all_clear()">重置</span>
		<span class="yj-button" onclick="hide_mask()">关闭</span>
	</div>
</div> 

<script language="javascript" type="text/javascript">
var Path = new Object();
Path.Skin = "{G_TEMPLATES_STYLE}";
Path.Webpath = "{WEB_PATH}";

var Base = {
    head: document.getElementsByTagName("head")[0] || document.documentElement,
    Myload: function(B, A) {
        this.done = false;
        B.onload = B.onreadystatechange = function() {
            if (!this.done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
                this.done = true;
                A();
                B.onload = B.onreadystatechange = null;
                if (this.head && B.parentNode) {
                    this.head.removeChild(B)
                }
            }
        }
    },
    getScript: function(A, C) {
        var B = function() {};
        if (C != undefined) {
            B = C
        }
        var D = document.createElement("script");
        D.setAttribute("language", "javascript");
        D.setAttribute("type", "text/javascript");
        D.setAttribute("src", A);
        this.head.appendChild(D);
        this.Myload(D, B)
    },
    getStyle: function(A, B) {
        var B = function() {};
        if (callBack != undefined) {
            B = callBack
        }
        var C = document.createElement("link");
        C.setAttribute("type", "text/css");
        C.setAttribute("rel", "stylesheet");
        C.setAttribute("href", A);
        this.head.appendChild(C);
        this.Myload(C, B)
    }
}

function GetVerNum() {
    var D = new Date();
    return D.getFullYear().toString().substring(2, 4) + '.' + (D.getMonth() + 1) + '.' + D.getDate() + '.' + D.getHours() + '.' + (D.getMinutes() < 10 ? '0' : D.getMinutes().toString().substring(0, 1))
}
Base.getScript('{G_TEMPLATES_JS}/mobile/Bottom.js');

/*选号相关方法 start  yjmp*/

var choice_id = '';
var list_id = '';
var code_list = new Array();
var used = new Array();
//隐藏蒙层  
function hide_mask() {
    $(".yj-mask").css('display', 'none');
    $(".yj-content").css('display', 'none');
    used.splice(0,used.length)
}

//显示云购码输入框 (可用数内)
function input_yg_code(item) {
    $(".yj-mask").css('display', 'block');
    $(".yj-content").css('display', 'block');
    choice_id = item.id;
    list_id = "s" + item.id;
    var listId = "txtNum" + item.id;

    reset_ygcode_list();
    var times = $("#" + listId).val();

    $('#yj-table').html("");

    var money = parseInt(cartListInfo[choice_id]['yjmoney']);
    var placeholder = '输入1-'+money+'之间的任意值';

    for (var i = 0; i < times; i++) {
        $('#yj-table').append("<tr><td class='yj-input' align='right' width='60%'><input type='number' name='ygcode' class='ygcode' value='' placeholder='"+placeholder+"' onkeyup ='check_input(this)' /></td><td class='yj-random'><span class='single_rand' onclick='single_rand(this)' >机选</span></td></tr>");
    }
}

/*检查输入内容*/
function check_input(obj){
    var money = parseInt(cartListInfo[choice_id]['yjmoney'])
    if (obj.value > money) {
        obj.value = ''
        alert('请输入1-'+money+'之间任意值')
    }
}

//单个随机 
function single_rand(item) {
    var yjkey = 0;
    var count = 1;
    $.ajax({
        url:'{WEB_PATH}/member/cart/single_rand',
        type:'POST',
        dataType:'JSON',
        data:{'num':count,'used':used,'shopid':choice_id},
        success:function(e){
            code_list = e.content
            $('.single_rand').each(function(key,object){
                if (object == item) {
                    yjkey = key
                }
            });

            $('.ygcode').each(function(key,object){
                if (key == yjkey) {
                    console.log($(object).val())
                    var old_val = $.trim($(object).val())
                    if (used.length > 0 && old_val.length > 0) {
                        for (var i = 0; i < used.length; i++) {
                            if (old_val == used[i]) {
                                used.splice(i,1)
                            }
                        }
                    }
                    $(object).val(code_list[0])
                    used.push(code_list[0])
                    console.log(used)
                }
            });
        },
        error:function(e){
            alert('网络错误')
        }
    });

}
//全部随机方法  
function all_rand() {
    all_clear()
    var count = $('.ygcode').length

    $.ajax({
        url:'{WEB_PATH}/member/cart/single_rand',
        type:'POST',
        dataType:'JSON',
        data:{'num':count,'used':used,'shopid':choice_id},
        success:function(e){
            code_list = e.content
            $('.ygcode').each(function(key,object){
                $(object).val(code_list[key])
                used.push(code_list[key])
            });
        },
        error:function(e){
            alert('网络错误')
        }
    });
}

//生成云购码(随机)  
function get_rand_code() {
    var length = cartListInfo[choice_id]['temp_list'].length
    var pos = Math.round(Math.random() * (length - 1))
    var code = cartListInfo[choice_id]['temp_list'][pos]
    return code
}

//检查输入框内是否有重码 重复返回0 不重复返回1
function check_same() {
    var err = 1
    $('.ygcode').each(function(key, object) {
        $('.ygcode').each(function(key1, object1) {
            if (object.value == object1.value && object1 != object && object.value != '') {
                err = 0
            }
        });
    });
    return err
}

//检查是否存在不可用验证码(不在序列里的)
function unuseable_msg() {

    var code_arr = cartListInfo[choice_id]['temp_list'];
    var err = 1;
    var err_msg = '';

    $('.ygcode').each(function(key, object) {
        for (var i = 0; i < code_arr.length; i++) {
            if (object.value == code_arr[i]) {
                err = 0;
            }
        }

        if (err) {
            err_msg += object.value
            err_msg += ','
        }
        err = 1;
    });

    if (err_msg != '') {
        err_msg = '云购码：' + err_msg + '格式错误或已被使用'
    }

    return err_msg
}

//全部清空处理 
function all_clear() {
    $('.ygcode').each(function(key, object) {
        $(object).val('')
    });
    used.splice(0,used.length)
}

//确定
function code_ok() {
    var err = 0
    var err_msg = ''
    var unuseable_err = unuseable_msg() //合法性

    $('.ygcode').each(function(key, object) {
        if (object.value == '') {
            err = 1
        }
    });

    if (err == 1) {
        err_msg += "云购码不能为空\n";
    }

    if (unuseable_err != '') {
        err_msg += unuseable_err
    }

    if (err_msg != '') {
        alert(err_msg)
    } else {
        hide_mask()
        var temp_code = get_temp_ygcode()
            //$("#"+choice_id).css('display','none')
        $("#" + list_id).html(temp_code)
            //数据存入info
        cartListInfo[choice_id].ygcode = temp_code
        $("#" + list_id).css('display', 'block')
        $.ajax({
            url: Gobal.Webpath + 'mobile/ajax/addygcode',
            type: 'POST',
            dataType: 'text',
            data: {
                'id': choice_id,
                'ygcode': temp_code
            },
            success: function() {
                console.log('添加成功')
            },
            error: function() {
                console.log('添加失败')
            }
        });
    }
}

/**
 * 获取临时云购码
 * @return {string} 逗号隔开的所有去购码
 */
function get_temp_ygcode() {
    var temp_code = ''
    $('.ygcode').each(function(key, object) {
        temp_code += $(object).val()
        temp_code += ','
    });

    var length = temp_code.length - 1
    temp_code = temp_code.substr(0, length)
    return temp_code
}

/**
 * 重选
 * @param  {int} val shoplistId
 */
function re_sel(val) {
    $("#" + val).css('display', 'block')
    $("#s" + val).css('display', 'none')
    list_id = ''
    if (used) {
        used.splice(0,used.length)
    }
}

/**
 * 检查云购码输入
 */
function check_ygcode() {
    var err = 0
        //yj-xj
    $('.yj-xj').each(function(key, object) {
        if ($(object).css('display') == 'block') {
            err = 1
        }
    });
    if (err) {
        alert('云购码没有输完')
        return false
    } else {
        return true
    }
}
/**
 * 返回选择商品的可用云购码数组
 * @param  商品id shopid 商品id
 * @return {array}   可用去购码数组
 */
function get_usable_ygcode(shopid) {

    var id_arr = cartListInfo[choice_id]['ygcode_list'].split(',')
    return id_arr
}

/**
 * 重置临时数据云购码序列
 */
function reset_ygcode_list() {

    var id_arr = get_usable_ygcode(choice_id)
    cartListInfo[choice_id]['temp_list'] = id_arr
}
/*选号相关方法 end  yjmp*/


/*添加购物车方法start yjmp*/
//添加到购物车
$(document).on("click",'.add2',function(){
	var codeid=$(this).attr('codeid');
	$.getJSON('{WEB_PATH}/mobile/ajax/addShopCart/'+codeid+'/1',function(data){
		if(data.code==1){
			alert('添加失败');
		}else if(data.code==0){
			location.reload(); 		
		}return false;
	});
});
/*添加购物车方法end yjmp*/
</script>


</div>
</body>
</html>